<!--
 * @Author: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @Date: 2024-08-29 10:59:23
 * @LastEditors: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @LastEditTime: 2024-10-21 14:30:58
 * @FilePath: \ft-apply-admin\src\views\applicationDetails\RTComponent\InterviewTache\Train\TrainComponent\TraingExamine.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <a-textarea style="width: 100%;" v-model:value="comment" @input="setLocal" showCount :maxlength="1000"
    placeholder="请填写考核评价" :autoSize="{ minRows: 4, maxRows: 4 }" />
  <div class="btns">
    <Button v-auth="'assessProgress'" color="success" @click="pass">通过</Button>
    <Button v-auth="'assessEliminate'" color="#E85B5B" @click="dieout">淘汰</Button>
  </div>
  <NoticeModal ref="modal" title="考核评价" @confirm='confirm'></NoticeModal>
</template>

<script setup lang='ts'>
import { Button } from "@/components/Button";
import { ref, onMounted } from "vue"
import { message } from "ant-design-vue";
import { addExamineAssess, checkIsExistExamineAssess } from "@/api/application-details/index.ts";
import { comStores } from '@/store/common/comStore';
import NoticeModal from "@/views/applicationDetails/Modals/NoticeModal.vue";
const store = comStores()
const { userName } = store.userInFor
const comment = ref<string>("")
const emits = defineEmits(['dieOut']);
const modal = ref<any>(null);
const type = ref<string>('')
onMounted(() => {
  comment.value = localStorage.getItem("考核评价") || '';
})
const pass = async () => {
  type.value = "通过"
  const res = await validate();
  // if (!res) return
  // send()
}
const dieout = async () => {
  console.log('dieout  考核');
  type.value = "淘汰"
  const res = await validate();
  // if (!res) return
  // send()
}

const confirm = async (flag) => {
  console.log(flag,'flag')
  modal.value.closeModal()
  if (!flag) {
    send()
  }
  // await send()
}
const validate = async () => {
  if (comment.value.trim() == "") return message.error("评价不能为空");
  const { resumeId, processId } = store.currentResume;
  const { userName } = store.userInFor
  const data = await checkIsExistExamineAssess({
    resumeId,
    processId,
    operator: userName,
  });
  if (data && data.code=='10000') {
    if(data.data){
      modal.value.showDialog(true)
    }else{
      modal.value.showDialog(false)
    }
  } else {
    message.error(data.msg)
  }
}
const send = async () => {
  localStorage.setItem('考核评价', "");
  const { resumeId, processId } = store.currentResume;
  if (comment.value.trim() == "") return message.error("评价不能为空");
  let param = {
    resumeId: resumeId,
    processId: processId,
    assess: comment.value,
    result: type.value,
    operator: userName
  }
  const data = await addExamineAssess(param);
  if (data && data.code === '10000') {
    message.success("操作成功");
    store.getResumeInfo(resumeId)
    store.$patch({
      noticeNumber: Math.random()
    })
    comment.value = ""
  } else {
    message.error(data.msg)
  }
}
const setLocal = () => {
  localStorage.setItem('考核评价', comment.value);
}
</script>
<style lang="less" scoped>
.btns {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
</style>